package com.xindaoapp.happypet.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xindao.photonics.fragments.manager.BaseFragment;
import com.xindaoapp.happypet.R;
import com.xindaoapp.happypet.activity.MyOrderListActivity;
import com.xindaoapp.happypet.utils.CommonUtil;
import com.xindaoapp.happypet.utils.Constants;

/**
 * 支付成功
 * 
 * @author chenghao
 * 
 */
public class OrderSuccessFragment extends BaseFragment {
    private String orderNumber;
    private float orderPrice;
    private String tittle;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.layout_order_success, container, false);
    }

    @Override
    protected void initEvents() {
        super.initEvents();
        getView().findViewById(R.id.online_pay).setOnClickListener(mOnClickListener);
    }

    private final OnClickListener mOnClickListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            // 订单提交成功后的在线支付按钮
                case R.id.online_pay:
                    Bundle bundle = new Bundle();
                    bundle.putString(Constants.KEY_ORDER_TITLE, tittle);
                    bundle.putString(Constants.KEY_ORDER_NUMBER, orderNumber);
                    // bundle.putFloat(Constants.KEY_ORDER_TOTAL_PRICE, 0.01f);
                    bundle.putFloat(Constants.KEY_ORDER_TOTAL_PRICE, orderPrice);
                    startFragment(new CheckstandFragment(), bundle);
                    break;

                default:
                    break;
            }
        }
    };

    // 订单提交成功后，点击完成按钮
    @Override
    protected void setRightViewListener(View view) {
        super.setRightViewListener(view);
        view.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MyOrderListActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra("submitOrder", true);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void initViews(View view) {
        super.initViews(view);
        orderNumber = getArguments().getString(Constants.KEY_ORDER_NUMBER);
        tittle = getArguments().getString(Constants.KEY_ORDER_TITLE);
        orderPrice = getArguments().getFloat(Constants.KEY_ORDER_TOTAL_PRICE);
        ((TextView) view.findViewById(R.id.order_number)).setText(orderNumber);
        ((TextView) view.findViewById(R.id.order_price)).setText("￥"
                + CommonUtil.transitionToFloat(orderPrice));
    }

    @Override
    protected String getTitleName() {
        return "提交成功";
    }

    @Override
    protected String getRightName() {
        return "完成";
    }

    @Override
    protected boolean showBackButton() {
        return false;
    }

}
